/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.log;

import deatax.Player;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

/**
 *
 * @author pson
 */
public class ActionLog {
    
    LinkedList<LogEntry> history;

    public ActionLog() {
        history = new LinkedList<LogEntry>();
    }
    
    
    public void addMessage(Player actor, String log, String desc) {
        history.push(new LogEntry(actor, log, desc));
    }
    
    /**
     * Will return all of the previous player's log entries in REVERSE order
     * @param p The current player. All of the entries of this player are ignored
     * until another player is found to take the place.
     * @return 
     */
    public LinkedList<LogEntry> getLastPlayerLog(Player p) {
        Player check = p;
        Player found = null;
        Iterator<LogEntry> it = history.iterator();
        LinkedList<LogEntry> log = new LinkedList<LogEntry>();
        while (it.hasNext()) {
            LogEntry le = it.next();
            if (found == null && check != le.actor) {
                found = le.actor;
                log.push(le);
            } else if (found != null && found == le.actor) {
                log.push(le);
            } else {
                break;
            }
        }
        return log;
    }
    
    
    
}
